< previous page page_264 next page >

Page 264
Solution 31
File Operations, Part 2
How do you start dealing with a problem like this? Just as I did: Take it step by step. In the puzzle, I mentioned it took me about two hours to solve it. As a result, the steps I went through are still fresh in my mind.
Check the Structures
The first step is always to double-check your declarations. In this case, the only new declaration is the SHNAMEMAPPING structure, which was defined as follows in C and in Visual Basic:
typedef struct _SHNAMEMAPPING { // shnm
    LPSTR pszOldPath; // address of old path name
    LPSTR pszNewPath; // pointer to new path name
    int   cchOldPath; // number of characters in old path name
    int   cchNewPath; // number of characters in new path name
} SHNAMEMAPPING, FAR *LPSHNAMEMAPPING;

Private Type SHNAMEMAPPING
        pszOldPath As String
        pszNewPath As String
        cchOldPath As Long
        cchNewPath As Long
End Type
When you see dynamic strings inside of structures, the very first question to ask is whether there is any chance that the API function will attempt to modify those fields. If the answer is yes, you can't use dynamic strings. This is discussed at length in Tutorial 7, ''Classes, Structures, and User-Defined Types" (in Part III of this book). Since the structure here is loaded by the API function itself and the pszOldPath and pszNewPath parameters are both regular NULL-terminated strings (LPSTR), it's clear that these parameters must not be defined as String.

 
< previous page page_264 next page >